package com.wsb.wetchat.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

/**
 * @author wang shaobo
 * @date 2022/6/22  15:26
 */
@Component
public class RedisUtils {

    @Resource
    private RedisTemplate<String, Object>  redisTemplate;




    public void set(String key,String value){

        redisTemplate.setStringSerializer(new StringRedisSerializer());
        redisTemplate.opsForValue().set(key,value);

    }


    public String getValue(String key){

        return (String) redisTemplate.opsForValue().get(key);

    }


    public void delKey(String key){
        redisTemplate.delete(key);
    }


    public boolean setNx(String key,String value){

        return redisTemplate.opsForValue().setIfAbsent(key,value);
    }


    public void setHashCach(Object key, Map map){

        redisTemplate.opsForHash().putAll(String.valueOf(key),map);

    }

    public List<Object> getHashCache(String key){


        return redisTemplate.opsForHash().values(key);

    }

    public Map getHashEntry(String key){

        return redisTemplate.opsForHash().entries(key);

    }


    public void zadd(String key){

        redisTemplate.opsForZSet().add(key,"",0);



    }







}
